// command_group_code 命令码
// command_group_key 区分码
// command_group_buffer 写入的数据体
// command_group_forcebuffer 强制覆盖数据体内容

// 特殊指令需要合并
var COMMAND_CONFIG = {
	index_charge_switch: {
		command_group_code: 0xfb,
		command_group_key: 0x01,
		command_group_buffer: [],
		command_group_forcebuffer: [],
	},
	index_discharge_switch: {
		command_group_code: 0xfb,
		command_group_key: 0x00,
		command_group_buffer: [],
		command_group_forcebuffer: [],
	},
	auto_balance: {
		command_group_code: 0x0a,
		command_group_buffer: [0x07, 0x00],
		command_group_forcebuffer: [],
	},
	clear_alarm: {
		command_group_code: 0x0a,
		command_group_buffer: [0x04, 0x00],
		command_group_forcebuffer: [],
	},
	reset_capacity: {
		command_group_code: 0x0a,
		command_group_buffer: [0x01, 0x00],
		command_group_forcebuffer: [],
	},
	current_calibration: {
		command_group_code: 0xad,
		command_group_buffer: [],
		command_group_forcebuffer: [],
		// command_task_code: 0xad,
	},

	default_mode: {
		command_group_code: 0x0a,
		command_group_buffer: [0x11, 0x00],
		command_group_forcebuffer: [],
	},
	quick_charge_mode: {
		command_group_code: 0x0a,
		command_group_buffer: [0x11, 0x01],
		command_group_forcebuffer: [],
	},
	uniform_charge: {
		command_group_code: 0x0a,
		command_group_buffer: [0x11, 0x02],
		command_group_forcebuffer: [],
	},
};

// 根据表单key来分发不同的方法执行
// method_association有下列关键key的使用method_name的方法
var COMMAND_METHOD_DESIGNATE = [
	{
		method_name: 'CLICK_DEFAULT_SWITCH',
		method_association: ['DEFAULT_SWITCH'],
	},
	{
		method_name: 'CLICK_MOS_SWITCH',
		method_association: ['MOS_SWITCH'],
	},
	{
		method_name: 'COMMAND_CONFIRM_POPUP',
		method_association: ['CONFIRM_POPUP', 'MODE_SELECT'],
	},
	{
		method_name: 'COMMAND_CHANGE_POPUP',
		method_association: ['CHANGE_POPUP', 'PARAMETER_NUMBER'],
	},
	{
		method_name: 'COMMAND_SELECT_PICKER',
		method_association: ['SELECT_PICKER'],
	},
];

// 页面渲染
var PAGE_RENDER_COMMADN_VIEW = {
	PAGE_INDEX: [
		{
			line_tt: '',
			view_type: 'battery_info',
			view_class: 'battery_show',
			view_list: [
				{ form_key: 'bluetooth_device_name', view_tt: '蓝牙名称' },
				{ form_key: 'dev_id', view_tt: '设备编号' },
				{
					form_key: 'dev_capacity',
					view_tt: '剩余容量',
					unit: 'AH',
					accuracy: 0.01,
					decimal: 2,
				},
				{ form_key: 'index_data_refresh_time', view_tt: '数据刷新时间' },
			],
		},
		{
			line_tt: '',
			view_type: 'switch_list',
			view_class: 'switch_list_c',
			view_list: [
				{ form_key: 'index_charge_switch', view_tt: '充电开关' },
				{ form_key: 'index_discharge_switch', view_tt: '放电开关' },
				{ form_key: 'index_protection_status_switch', view_tt: '保护状态' },
				{ form_key: 'index_balance_status_switch', view_tt: '均衡状态' },
			],
		},
		{
			line_tt: '基础信息',
			view_type: 'info_list',
			view_class: 'info_list_c',
			view_list: [
				{
					form_key: 'dev_voltage',
					icon: '/static/images/info_1.png',
					view_tt: '总电压',
					unit: 'V',
					accuracy: 0.01,
					decimal: 2,
				},
				{
					form_key: 'dev_current',
					icon: '/static/images/info_2.png',
					view_tt: '电流',
					unit: 'A',
					accuracy: 0.01,
					decimal: 2,
				},
				{
					form_key: 'index_power',
					icon: '/static/images/info_3.png',
					view_tt: '功率',
					unit: 'W',
					accuracy: 0.01,
					decimal: 2,
				},
				{
					form_key: 'dev_max',
					icon: '/static/images/info_4.png',
					view_tt: '最高电压',
					unit: 'V',
					accuracy: 0.001,
					decimal: 3,
					decimal_user: 2,
				},
				{
					form_key: 'dev_min',
					icon: '/static/images/info_5.png',
					view_tt: '最低电压',
					unit: 'V',
					accuracy: 0.001,
					decimal: 3,
					decimal_user: 2,
				},
				{
					form_key: 'dev_diff',
					icon: '/static/images/info_6.png',
					view_tt: '压差',
					unit: 'V',
					accuracy: 0.001,
					decimal: 3,
					decimal_user: 2,
				},
				{
					form_key: 'dev_avg',
					icon: '/static/images/info_7.png',
					view_tt: '平均电压',
					unit: 'V',
					accuracy: 0.001,
					decimal: 3,
					decimal_user: 2,
				},
				{
					form_key: 'dev_circulate',
					icon: '/static/images/info_8.png',
					view_tt: '循环次数',
				},
				{
					form_key: 'dev_bunch',
					icon: '/static/images/info_9.png',
					view_tt: '串数',
				},
			],
		},
		{
			line_tt: '温度',
			view_type: 'index_temperature',
			view_class: 'heat_c',
			view_list: [],
		},
		{
			line_tt: '单串电压',
			view_type: 'index_voltage_chart',
			view_class: 'voltage_c',
			view_list: [],
		},
		{
			line_tt: '报警',
			view_type: 'warning_list',
			view_class: 'warning_c',
			view_list: [
				// {
				//     view_tt: '充电过温保护',
				//     form_key: '',
				//     time: '12-12 12:05:10',
				//     status: -1
				// },
			],
		},
	],
	PAGE_CONTROL: [
		{
			line_tt: '电池控制',
			view_type: 'battery_control',
			view_class: 'battery_control_c',
			view_list: [
				{
					form_key: 'index_charge_switch',
					tips_key: 'bms_tip_index_charge_switch',
					view_tt: '充电开关',
					can_click: true,
					click_type: 'switch',
					method_association_key: 'MOS_SWITCH',
				},
				{
					form_key: 'index_discharge_switch',
					tips_key: 'bms_tip_index_discharge_switch',
					view_tt: '放电开关',
					can_click: true,
					click_type: 'switch',
					method_association_key: 'MOS_SWITCH',
				},
			],
		},
		{
			line_tt: '充电模式选择',
			view_type: 'mode_select',
			view_class: 'mode_select_c',
			tips_key: 'bms_tip_mode_select',
			view_list: [
				{
					form_key: 'default_mode',
					icon: '/static/images/mode_1.png',
					view_tt: '默认模式',
					content: '选择默认模式？',
					click_type: 'mode_select',
					// cmd_type: 0x0a,
					// buffer: [0x11, 0x00],
					method_association_key: 'MODE_SELECT',
				},
				{
					form_key: 'quick_charge_mode',
					icon: '/static/images/mode_2.png',
					view_tt: '快充模式',
					content: '选择快充模式？',
					click_type: 'mode_select',
					// cmd_type: 0x0a,
					// buffer: [0x11, 0x01],
					method_association_key: 'MODE_SELECT',
				},
				{
					form_key: 'uniform_charge',
					icon: '/static/images/mode_3.png',
					view_tt: '均衡充电',
					content: '选择均衡充电？',
					click_type: 'mode_select',
					// cmd_type: 0x0a,
					// buffer: [0x11, 0x02],
					method_association_key: 'MODE_SELECT',
				},
				// {
				// 	form_key: 'scheduled_charge',
				// 	icon: '/static/images/mode_4.png',
				// 	view_tt: '定时充电',
				// 	content: '选择定时充电？',
				// 	click_type: 'mode_select',
				// 	cmd_type: 0x0a,
				// 	buffer: [0x11, 0x03],
				// },
				// {
				// 	form_key: 'stop_charge',
				// 	icon: '/static/images/mode_5.png',
				// 	view_tt: '停止充电',
				// 	content: '选择停止充电？',
				// 	click_type: 'confirm',
				// 	cmd_type: 0x0a,
				// 	buffer: [0x11, 0x04],
				// },
			],
		},
		{
			line_tt: '电池设置',
			view_type: 'battery_setting',
			view_class: 'battery_setting_c',
			view_list: [
				{
					form_key: 'auto_balance',
					icon: '/static/images/setting_1.png',
					view_tt: '自动均衡',
					content: '确认自动均衡？',
					click_type: 'confirm',
					method_association_key: 'CONFIRM_POPUP',
				},
				{
					form_key: 'current_calibration',
					icon: '/static/images/setting_2.png',
					view_tt: '电流校准',
					unit: 'A',
					placeholder: '请输入电流校准（A）',
					method_association_key: 'CHANGE_POPUP',
				},
				{
					form_key: 'voltage_calibration',
					icon: '/static/images/setting_3.png',
					view_tt: '电压校准',
					url: '/pagesA/index/setting_detail?type=voltage_calibration',
				},
				{
					form_key: 'clear_alarm',
					icon: '/static/images/setting_4.png',
					view_tt: '清除告警',
					content: '确认清除告警？',
					click_type: 'confirm',
					method_association_key: 'CONFIRM_POPUP',
				},
				{
					form_key: 'reset_capacity',
					icon: '/static/images/setting_5.png',
					view_tt: '重置容量',
					content: '确认重置容量？',
					click_type: 'confirm',
					method_association_key: 'CONFIRM_POPUP',
				},
			],
		},
	],
	PAGE_SETTING_DETAIL: {
		information: {
			line_tt: '基本信息',
			view_type: 'information',
			view_list: [
				{
					view_tt: '蓝牙名称',
					form_key: 'bluetooth_device_name',
					unit: '',
					can_click: true,
					value_type: 'ascii_nolength',
					cmd_type: 0x07,
					inp_type: 'text',
				},
				// {
				// 	view_tt: '序号',
				// 	form_key: 'information_serialNumber',
				// 	unit: '',
				// 	can_click: false,
				// 	document_start_number: 6
				// },
				{
					view_tt: '条码',
					form_key: 'information_barcode',
					unit: '',
					can_click: false,
					document_start_number: 88,
					byte: 32,
					value_type: 'ascii',
				},
				{
					view_tt: '电池型号',
					form_key: 'information_batteryModel',
					unit: '',
					can_click: false,
					document_start_number: 158,
					byte: 24,
					// value_type: 'ascii_rever'
					value_type: 'ascii',
				},
				{
					view_tt: '电池生产商',
					form_key: 'information_batteryManufacturer',
					unit: '',
					can_click: false,
					document_start_number: 56,
					byte: 32,
					value_type: 'ascii',
				},
				{
					view_tt: 'BMS版本号',
					form_key: 'index_software_version',
					unit: '',
					can_click: false,
				},
				{
					view_tt: 'BMS型号',
					form_key: 'information_bmsModel',
					unit: '',
					can_click: false,
					document_start_number: 176,
					byte: 16,
					// value_type: 'ascii_rever'
					value_type: 'ascii',
				},
				{
					view_tt: '生产日期',
					form_key: 'information_productionDate',
					unit: '',
					can_click: false,
					document_start_number: 5,
					value_type: 'produce_date',
				},
				{
					view_tt: 'BMS地址',
					form_key: 'information_bmsAddress',
					unit: '',
					can_click: false,
					document_start_number: 170,
					byte: 12,
					value_type: 'information_bmsAddress',
				},
				{
					view_tt: '额定充电电流',
					form_key: 'information_ratedChargeCurrent',
					unit: 'A',
					can_click: false,
					document_start_number: 119,
				},
				{
					view_tt: '额定放电电流',
					form_key: 'information_ratedDischargeCurrent',
					unit: 'A',
					can_click: false,
					document_start_number: 118,
				},
			],
		},
		initialize: {
			line_tt: '初始设置',
			view_type: 'initialize',
			view_list: [
				{
					view_tt: '标称容量',
					form_key: 'initialize_nominal_capacity',
					unit: 'mAh',
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					document_start_number: 0,

					can_click: true,
				},
				{
					view_tt: '循环容量',
					form_key: 'initialize_cycle_capacity',
					unit: 'mAh',
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					document_start_number: 1,

					can_click: true,
				},
				// {
				// 	view_tt: "系统功耗",
				// 	form_key: "initialize_system_consumption",
				// 	document_start_number: 4,
				// 	unit: "mA",
				// 	can_click: true
				// },

				// 学习容量
				{
					view_tt: '满充容量',
					form_key: 'learning_capacity',
					unit: 'mAh',
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					document_start_number: 112,
					can_click: true,
				},

				// {
				// 	view_tt: "满充容量",
				// 	form_key: "initialize_full_charge_capacity",
				// 	unit: "mAh",
				// 	unit_read_compute: 0.01,
				// 	unit_read_conversion: 1000,
				// 	can_click: true,
				// 	type: '0x03'
				// },
				{
					view_tt: '串数',
					form_key: 'initialize_series_number',
					document_start_number: 31,
					can_click: true,
				},
			],
		},
		protection_parameters: {
			line_tt: '保护参数',
			view_type: 'protection_parameters',
			view_list: [
				{
					view_tt: '单体过压保护',
					form_key: 'protection_parameters_overvoltage_protection',
					unit: 'mV',
					document_start_number: 20,
					can_click: true,
				},
				{
					view_tt: '单体过压释放',
					form_key: 'protection_parameters_overvoltage_recovery',
					unit: 'mV',
					document_start_number: 21,
					can_click: true,
				},
				{
					view_tt: '单体过压延时',
					form_key: 'protection_parameters_overvoltage_delay',
					unit: 's',
					document_start_number: 51,
					can_click: true,
				},
				{
					view_tt: '单体欠压保护',
					form_key: 'protection_parameters_undervoltage_protection',
					unit: 'mV',
					document_start_number: 22,
					can_click: true,
				},
				{
					view_tt: '单体欠压释放',
					form_key: 'protection_parameters_undervoltage_recovery',
					unit: 'mV',
					document_start_number: 23,
					can_click: true,
				},
				{
					view_tt: '单体欠压延时',
					form_key: 'protection_parameters_undervoltage_delay',
					unit: 's',
					document_start_number: 50,
					can_click: true,
				},
				{
					view_tt: '总压过压保护',
					form_key: 'protection_parameters_total_overvoltage_protection',
					unit: 'mV',
					document_start_number: 16,
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,

					can_click: true,
				},
				{
					view_tt: '总压过压释放',
					form_key: 'protection_parameters_total_overvoltage_recovery',
					unit: 'mV',
					document_start_number: 17,
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					can_click: true,
				},
				{
					view_tt: '总压过压延时',
					form_key: 'protection_parameters_total_overvoltage_delay',
					unit: 's',
					document_start_number: 49,
					can_click: true,
				},
				{
					view_tt: '总压欠压保护',
					form_key: 'protection_parameters_total_undervoltage_protection',
					unit: 'mV',
					document_start_number: 18,
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					can_click: true,
				},
				{
					view_tt: '总压欠压释放',
					form_key: 'protection_parameters_total_undervoltage_recovery',
					unit: 'mV',
					unit_read_compute: 0.01,
					document_start_number: 19,
					unit_read_conversion: 1000,
					can_click: true,
				},
				{
					view_tt: '总压欠压延时',
					form_key: 'protection_parameters_total_undervoltage_delay',
					unit: 's',
					document_start_number: 48,
					can_click: true,
				},

				{
					view_tt: '硬件过压保护值',
					form_key: 'hardware_overvoltage_protection_value',
					unit: 'mV',
					document_start_number: 38,
					can_click: true,
				},
				{
					view_tt: '硬件欠压保护值',
					form_key: 'hardware_undervoltage_protection_value',
					unit: 'mV',
					document_start_number: 39,
					can_click: true,
				},
				{
					view_tt: '硬件过欠压延时',
					form_key: 'hardware_over_undervoltage_delay',
					unit: 's',
					document_start_number: 42,
					can_click: true,
				},
			],
		},

		protection_count: {
			line_tt: '保护次数',
			view_type: 'protection_count',
			view_list: [
				{
					view_tt: '短路保护次数',
					form_key: 'dev_preserve',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '充电过流次数',
					form_key: 'protection_count_charge_overcurrent',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '放电过流次数',
					form_key: 'protection_count_discharge_overcurrent',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '单体过压次数',
					form_key: 'protection_count_single_overvoltage',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '单体欠压次数',
					form_key: 'protection_count_single_undervoltage',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '充电高温次数',
					form_key: 'protection_count_charge_high_temperature',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '充电低温次数',
					form_key: 'protection_count_charge_low_temperature',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '放电高温次数',
					form_key: 'protection_count_discharge_high_temperature',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '放电低温次数',
					form_key: 'protection_count_discharge_low_temperature',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '整体过压次数',
					form_key: 'protection_count_total_overvoltage',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '整体欠压次数',
					form_key: 'protection_count_total_undervoltage',
					unit: '',
					can_click: false,
				},
				{
					view_tt: '系统重启次数',
					form_key: 'dev_restart',
					unit: '',
					can_click: false,
				},
			],
		},

		current_setting: {
			line_tt: '电流设置',
			view_type: 'current_setting',
			view_list: [
				{
					view_tt: '充电过流保护',
					form_key: 'current_setting_charge_overcurrent_protection',
					unit: 'mA',
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					document_start_number: 24,
					can_click: true,
				},
				{
					view_tt: '充电过流延时',
					document_start_number: 52,
					form_key: 'current_setting_charge_overcurrent_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '充电过流恢复延时',
					document_start_number: 53,
					form_key: 'current_setting_charge_overcurrent_recovery_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '放电过流保护',
					document_start_number: 25,
					form_key: 'current_setting_discharge_overcurrent_protection',
					unit: 'mA',
					unit_read_compute: 0.01,
					unit_read_conversion: 1000,
					can_click: true,
					inp_type: 'negative',
					value_type: 'is_current',
				},
				{
					view_tt: '放电过流延时',
					document_start_number: 54,
					form_key: 'current_setting_discharge_overcurrent_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '放电过流恢复延时',
					document_start_number: 55,
					form_key: 'current_setting_discharge_overcurrent_recovery_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '二级过流保护',
					document_start_number: 40,
					form_key: 'current_setting_secondary_overcurrent_protection',
					unit: 'A',
					can_click: true,
					click_type: 'select',
					link_config: [
						{
							link_k: 'current_setting_secondary_overcurrent_protection',
							link_ide: 'h',
						},
						{
							link_k: 'current_setting_secondary_overcurrent_delay',
							link_ide: 'l',
						},
					],
					value_type: 'low4_high4',
					method_association_key: 'SELECT_PICKER',
				},
				{
					view_tt: '二级过流延时',
					document_start_number: 40,
					form_key: 'current_setting_secondary_overcurrent_delay',
					unit: 'ms',
					can_click: true,
					click_type: 'select',
					link_config: [
						{
							link_k: 'current_setting_secondary_overcurrent_protection',
							link_ide: 'h',
						},
						{
							link_k: 'current_setting_secondary_overcurrent_delay',
							link_ide: 'l',
						},
					],
					value_type: 'low4_high4',
					method_association_key: 'SELECT_PICKER',
				},
				{
					view_tt: '短路保护',
					document_start_number: 41,
					form_key: 'current_setting_short_circuit_protection',
					unit: 'A',
					can_click: true,
					click_type: 'select',
					link_config: [
						{
							link_k: 'current_setting_short_circuit_protection',
							link_ide: 'h',
						},
						{
							link_k: 'current_setting_short_circuit_delay',
							link_ide: 'l',
						},
					],
					value_type: 'low4_high4',
					method_association_key: 'SELECT_PICKER',
				},
				{
					view_tt: '短路保护延时',
					document_start_number: 41,
					form_key: 'current_setting_short_circuit_delay',
					unit: 'uS',
					can_click: true,
					click_type: 'select',
					link_config: [
						{
							link_k: 'current_setting_short_circuit_protection',
							link_ide: 'h',
						},
						{
							link_k: 'current_setting_short_circuit_delay',
							link_ide: 'l',
						},
					],
					value_type: 'low4_high4',
					method_association_key: 'SELECT_PICKER',
				},
				{
					view_tt: '短路保护恢复延时',
					document_start_number: 43,
					form_key: 'current_setting_short_circuit_recovery_delay',
					unit: 's',
					can_click: true,
				},
			],
		},
		temperature_setting: {
			line_tt: '温度设置',
			view_type: 'temperature_setting',
			view_list: [
				{
					view_tt: '充电高温保护',
					form_key: 'temperature_setting_charge_high_temperature_protection',
					unit: '°C',
					value_type: 'is_temperature',
					document_start_number: 8,
					can_click: true,
				},
				{
					view_tt: '充电高温释放',
					document_start_number: 9,

					form_key: 'temperature_setting_charge_high_temperature_recovery',
					unit: '°C',
					value_type: 'is_temperature',
					can_click: true,
				},
				{
					view_tt: '充电高温延时',
					document_start_number: 45,

					form_key: 'temperature_setting_charge_high_temperature_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '充电低温保护',
					document_start_number: 10,

					form_key: 'temperature_setting_charge_low_temperature_protection',
					unit: '°C',
					value_type: 'is_temperature',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '充电低温释放',
					document_start_number: 11,

					form_key: 'temperature_setting_charge_low_temperature_recovery',
					unit: '°C',
					value_type: 'is_temperature',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '充电低温延时',
					document_start_number: 44,

					form_key: 'temperature_setting_charge_low_temperature_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '放电高温保护',
					document_start_number: 12,

					form_key: 'temperature_setting_discharge_high_temperature_protection',
					unit: '°C',
					value_type: 'is_temperature',
					can_click: true,
				},
				{
					view_tt: '放电高温释放',
					document_start_number: 13,

					form_key: 'temperature_setting_discharge_high_temperature_recovery',
					unit: '°C',
					value_type: 'is_temperature',
					can_click: true,
				},
				{
					view_tt: '放电高温延时',
					document_start_number: 47,

					form_key: 'temperature_setting_discharge_high_temperature_delay',
					unit: 's',
					can_click: true,
				},
				{
					view_tt: '放电低温保护',
					document_start_number: 14,

					form_key: 'temperature_setting_discharge_low_temperature_protection',
					unit: '°C',
					value_type: 'is_temperature',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '放电低温释放',
					document_start_number: 15,

					form_key: 'temperature_setting_discharge_low_temperature_recovery',
					unit: '°C',
					value_type: 'is_temperature',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '放电低温延时',
					document_start_number: 46,

					form_key: 'temperature_setting_discharge_low_temperature_delay',
					unit: 's',
					can_click: true,
				},
			],
		},
		balanced_setting: {
			line_tt: '均衡设置',
			view_type: 'balanced_setting',
			view_list: [
				{
					view_tt: '均衡电压',
					form_key: 'balanced_setting_balance_voltage',
					unit: 'mV',
					document_start_number: 26,

					can_click: true,
				},
				{
					view_tt: '均衡精度',
					form_key: 'balanced_setting_balance_accuracy',
					unit: 'mV',
					document_start_number: 27,
					can_click: true,
				},
				// 跟功能设置页面的均衡功能通用值
				{
					view_tt: '开启均衡',
					form_key: 'function_setting_balance',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '均衡方式',
					form_key: 'function_setting_balance_mode',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'select',
					method_association_key: 'SELECT_PICKER',
				},

				// {
				// 	view_tt: "温度探头配置",
				// 	form_key: "temperature_probe_configuration",
				// 	unit: "",
				// 	document_start_number: 30,
				// },

				// {
				// 	view_tt: "开关控制时间",
				// 	form_key: "switch_control_time",
				// 	unit: "s",
				// 	document_start_number: 32
				// },
				// {
				// 	view_tt: "LED工作时间",
				// 	form_key: "led_working_time",
				// 	unit: "s",
				// 	document_start_number: 33
				// },

				// {
				// 	view_tt: "BMS-编码信息",
				// 	form_key: "bms_encoding_information",
				// 	unit: "",
				// 	document_start_number: 72,
				// 	byte: 32,
				// 	value_type: 'ascii'
				// },
				// {
				// 	view_tt: "GPS关断电压",
				// 	form_key: "gps_shutdown_voltage",
				// 	unit: "mV",
				// 	document_start_number: 104
				// },
				// {
				// 	view_tt: "GPS关断延时",
				// 	form_key: "gps_shutdown_delay",
				// 	unit: "s",
				// 	document_start_number: 105
				// },

				// {
				// 	view_tt: "额定电压",
				// 	form_key: "BatteryVoltage",
				// 	unit: "mAV",
				// 	unit_read_compute: 0.1,
				// 	unit_read_conversion: 1000,
				// 	document_start_number: 114
				// },

				// {
				// 	view_tt: "额定电流",
				// 	form_key: "rated_current",
				// 	unit: "A",
				// 	document_start_number: 115
				// },

				// {
				// 	view_tt: "最大功率",
				// 	form_key: "maximum_power",
				// 	unit: "W",
				// 	document_start_number: 116
				// },

				// {
				// 	view_tt: "额定充电电压",
				// 	form_key: "rated_charging_voltage",
				// 	unit: "mAV",
				// 	unit_read_compute: 0.1,
				// 	unit_read_conversion: 1000,
				// 	document_start_number: 117
				// },

				// {
				// 	view_tt: "额定放电功率",
				// 	form_key: "rated_discharge_power",
				// 	unit: "W",
				// 	document_start_number: 120
				// },
			],
		},
		capacity_voltage_setting: {
			line_tt: '容量电压设置',
			view_type: 'capacity_voltage_setting',
			view_list: [
				{
					view_tt: '10%',
					form_key: 'capacity_voltage_setting_10_percent',
					unit: 'mV',
					document_start_number: 110,
					can_click: true,
				},
				{
					view_tt: '20%',
					form_key: 'capacity_voltage_setting_20_percent',
					unit: 'mV',
					document_start_number: 37,

					can_click: true,
				},
				{
					view_tt: '30%',
					form_key: 'capacity_voltage_setting_30_percent',
					unit: 'mV',
					document_start_number: 109,

					can_click: true,
				},
				{
					view_tt: '40%',
					form_key: 'capacity_voltage_setting_40_percent',
					unit: 'mV',
					document_start_number: 36,

					can_click: true,
				},
				{
					view_tt: '50%',
					form_key: 'capacity_voltage_setting_50_percent',
					unit: 'mV',
					document_start_number: 108,

					can_click: true,
				},
				{
					view_tt: '60%',
					form_key: 'capacity_voltage_setting_60_percent',
					unit: 'mV',
					document_start_number: 35,

					can_click: true,
				},
				{
					view_tt: '70%',
					form_key: 'capacity_voltage_setting_70_percent',
					unit: 'mV',
					document_start_number: 107,

					can_click: true,
				},
				{
					view_tt: '80%',
					form_key: 'capacity_voltage_setting_80_percent',
					unit: 'mV',
					document_start_number: 34,

					can_click: true,
				},
				{
					view_tt: '90%',
					form_key: 'capacity_voltage_setting_90_percent',
					unit: 'mV',
					document_start_number: 106,

					can_click: true,
				},
				{
					view_tt: '100%',
					form_key: 'capacity_voltage_setting_100_percent',
					unit: 'mV',
					document_start_number: 111,

					can_click: true,
				},
				{
					view_tt: '充满电压',
					form_key: 'capacity_voltage_setting_full_voltage',
					unit: 'mV',
					document_start_number: 2,

					can_click: true,
				},
				{
					view_tt: '放空电压',
					form_key: 'capacity_voltage_setting_empty_voltage',
					unit: 'mV',
					document_start_number: 3,

					can_click: true,
				},
			],
		},
		link_resistance: {
			line_tt: '链接内阻',
			view_type: 'link_resistance',
			view_list: [
				{
					view_tt: '第1串内阻',
					form_key: 'link_resistance_1',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第2串内阻',
					form_key: 'link_resistance_2',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第3串内阻',
					form_key: 'link_resistance_3',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第4串内阻',
					form_key: 'link_resistance_4',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第5串内阻',
					form_key: 'link_resistance_5',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第6串内阻',
					form_key: 'link_resistance_6',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第7串内阻',
					form_key: 'link_resistance_7',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第8串内阻',
					form_key: 'link_resistance_8',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第9串内阻',
					form_key: 'link_resistance_9',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第10串内阻',
					form_key: 'link_resistance_10',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第11串内阻',
					form_key: 'link_resistance_11',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第12串内阻',
					form_key: 'link_resistance_12',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第13串内阻',
					form_key: 'link_resistance_13',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第14串内阻',
					form_key: 'link_resistance_14',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第15串内阻',
					form_key: 'link_resistance_15',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第16串内阻',
					form_key: 'link_resistance_16',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第17串内阻',
					form_key: 'link_resistance_17',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第18串内阻',
					form_key: 'link_resistance_18',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第19串内阻',
					form_key: 'link_resistance_19',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第20串内阻',
					form_key: 'link_resistance_20',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第21串内阻',
					form_key: 'link_resistance_21',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第22串内阻',
					form_key: 'link_resistance_22',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第23串内阻',
					form_key: 'link_resistance_23',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第24串内阻',
					form_key: 'link_resistance_24',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第25串内阻',
					form_key: 'link_resistance_25',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第26串内阻',
					form_key: 'link_resistance_26',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第27串内阻',
					form_key: 'link_resistance_27',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第28串内阻',
					form_key: 'link_resistance_28',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第29串内阻',
					form_key: 'link_resistance_29',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
				{
					view_tt: '第30串内阻',
					form_key: 'link_resistance_30',
					unit: 'mR',
					inp_type: 'negative',
					can_click: true,
				},
			],
		},
		function_setting: {
			line_tt: '功能设置',
			view_type: 'function_setting',
			view_list: [
				{
					view_tt: '弱电开关',
					form_key: 'function_setting_switch',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '短路负载检测',
					form_key: 'function_setting_load_detection',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '开启均衡',
					form_key: 'function_setting_balance',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '均衡方式',
					form_key: 'function_setting_balance_mode',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'select',
					method_association_key: 'SELECT_PICKER',
				},
				{
					view_tt: '温控_1',
					form_key: 'function_setting_temp_1',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_2',
					form_key: 'function_setting_temp_2',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_3',
					form_key: 'function_setting_temp_3',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_4',
					form_key: 'function_setting_temp_4',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_5',
					form_key: 'function_setting_temp_5',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_6',
					form_key: 'function_setting_temp_6',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_7',
					form_key: 'function_setting_temp_7',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '温控_8',
					form_key: 'function_setting_temp_8',
					unit: '',
					can_click: true,
					document_start_number: 30,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: 'LED',
					form_key: 'function_setting_led',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: 'LED数量',
					form_key: 'function_setting_led_quantity',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: 'RTC',
					form_key: 'function_setting_rtc',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: 'FCC限制',
					form_key: 'function_setting_fcc_limit',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},

				{
					view_tt: '充电握手使能',
					form_key: 'function_setting_handshake_enable',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: 'GPS',
					form_key: 'function_setting_gps',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				{
					view_tt: '蜂鸣器使能',
					form_key: 'function_setting_buzzer_enable',
					unit: '',
					can_click: true,
					document_start_number: 29,
					click_type: 'switch',
					method_association_key: 'DEFAULT_SWITCH',
				},
				// {
				// 	view_tt: "电池模式",
				// 	form_key: "function_setting_battery_mode",
				// 	unit: "",
				// 	can_click: true,
				// 	document_start_number: 29,
				// 	click_type: "switch"
				// },
				// {
				// 	view_tt: "电流容量",
				// 	form_key: "function_setting_current_capacity",
				// 	unit: "",
				// 	can_click: true,
				// 	document_start_number: 29,
				// 	click_type: "switch"
				// }
			],
		},
		system_setting: {
			line_tt: '系统设置',
			view_type: 'system_setting',
			view_list: [
				{
					view_tt: '识别电流',
					form_key: 'system_setting_recognition_current',
					unit: 'mA',
					can_click: true,
					document_start_number: 121,
					click_type: '',
				},
				{
					view_tt: '休眠时间',
					form_key: 'system_setting_sleep_time',
					unit: 's',
					can_click: true,
					document_start_number: 122,
					click_type: '',
				},
				// {
				// 	view_tt: "预留告警参数",
				// 	form_key: "reserve_alarm_parameters",
				// 	can_click: true,
				// 	document_start_number: 123,
				// 	click_type: "",
				// 	byte: 70
				// },

				{
					view_tt: '容量修正间隔',
					form_key: 'system_setting_capacity_correction_interval',
					unit: 's',
					document_start_number: 113,

					can_click: true,
					click_type: '',
				},
				{
					view_tt: '串数',
					form_key: 'initialize_series_number',
					can_click: true,
					click_type: '',
				},
				{
					view_tt: '检流阻值',
					form_key: 'system_setting_current_limit',
					unit: 'mR',
					document_start_number: 28,

					can_click: true,
					click_type: '',
				},
				{
					view_tt: '循环次数',
					form_key: 'system_setting_cycle_count',
					document_start_number: 7,
					can_click: true,
					click_type: '',
				},
			],
		},

		voltage_calibration: {
			line_tt: '电压校准',
			view_type: 'voltage_calibration',
			view_list: [],
		},
	},
};
module.exports = {
	INIT_BLUETOOTH_RESET_FORM() {
		let _this = this;
		uni.setStorageSync('BLUETOOTH_INIT_RESET_FORM', this.BLUETOOTH_INIT_FORM);
	},

	INIT_PAGE_COMMADN_VIEW(KEY) {
		let _this = this;
		_this.PAGE_VIEW = PAGE_RENDER_COMMADN_VIEW[KEY];
	},
	// 解析socket发送的修改指令
	HANDLE_SOCKET_TO_EDIT_BLUETOOTH(event) {
		let _this = this;
		// console.log(event);
		let { key, value } = event;
		let BACK = {};
		_this.find_to_handle({
			data: PAGE_RENDER_COMMADN_VIEW,
			find_fun: function (e) {
				let { data, attr_name, find_fun } = e;
				if (_this.gettype(data) == 'Object' && data['form_key'] == key) {
					data['popup_key'] = value;
					BACK = {
						item: data,
						value,
					};
				} else {
					return false;
				}
			},
		});
		// console.log(BACK, '----------------------------------');
		if (_this.objJudge(BACK)) {
			_this.COMMAND_TRANSFER(BACK);
		}
	},
	// 指令统一中转匹配不同方法
	COMMAND_TRANSFER(event) {
		let _this = this;
		let { item } = event,
			{ form_key, method_association_key = 'PARAMETER_NUMBER' } = item;
		let METHOD = _this.BACK_COMMAND_METHOD_NAME(method_association_key);
		_this[METHOD](event);
	},
	CLICK_MOS_SWITCH(event) {
		// MOS 0代表开启 1代表关闭
		// 组件switch返回的value为按钮点击前的状态
		// value 为0时说明 MOS需要开启，此时MOS应该为 0
		// log_value 上传操作日志用
		let _this = this;
		let { item, value } = event,
			{ form_key, method_association_key } = item,
			log_value = 0;
		if (!_this.bluetooth_operate_before_judge()) return;
		item = _this.INIT_COMMAND_CONFIG({ item });
		item['command_group_buffer'] = [item.command_group_key, value];
		log_value = value == 1 ? 0 : 1;
		_this.common_change({ item, value: log_value });
	},
	CLICK_DEFAULT_SWITCH(event) {
		let _this = this;
		let { item, value } = event,
			{ form_key, method_association_key } = item,
			log_value = 0;
		value = value == 1 ? 0 : 1;
		item = _this.INIT_COMMAND_CONFIG({ item });
		item['popup_key'] = _this.switch_getvalue_fun({ item, value });
		_this.common_change({ item, value });
	},
	COMMAND_SELECT_PICKER(event) {
		let { item, value, index } = event;
		console.log(event);
		let back_index = Number(index);
		let _this = this;
		let end_key = 0;
		item = _this.INIT_COMMAND_CONFIG({ item });
		if (item.form_key == 'function_setting_balance_mode') {
			// 均衡方式比较特殊 back_index只有 0 和 1状态
			end_key = _this.switch_getvalue_fun({ item, value: back_index });
		} else {
			// popup_key   需要根据back_index 配合另外一个设置
			// 取得高4 低4后 使用方法取得对应的数值 写入popup_key后触发 editInstruct_init 写入模式即可
			let h_l = { h: 0, l: 0 };
			// link_k link_ide
			item.link_config.forEach((vv, ii) => {
				if (vv.link_k == item.form_key) {
					h_l[vv.link_ide] = back_index;
					// vv.link_ide == 'h' ? 'l' : 'h'
				} else {
					// 另外一个取它默认的选择索引
					_this.find_to_handle({
						data: _this.page_data[_this.page_type],
						find_fun: function (e) {
							let { data, attr_name, find_fun } = e;
							// attr_name == 'form_key'
							if (_this.gettype(data) == 'Object' && data.form_key == vv.link_k) {
								// newobj.push(data)
								// _this.$set(data, 'select_list', select_list)
								// _this.$set(data, 'select_index', select_index)
								h_l[vv.link_ide] = Number(data.select_index);
							} else {
								return false;
							}
						},
					});
				}
			});
			end_key = _this.low4_high4_rever_fun(h_l.h, h_l.l);
		}
		item['popup_key'] = end_key;
		_this.common_change({ item, value: back_index });
	},
	COMMAND_CONFIRM_POPUP(event) {
		// 自动均衡 清除告警 重置容量
		let _this = this;
		let { item, value } = event,
			{ form_key, method_association_key } = item;
		if (!_this.bluetooth_operate_before_judge()) return;
		item = _this.INIT_COMMAND_CONFIG({ item });
		_this.common_change({ item });
	},
	COMMAND_CHANGE_POPUP(event) {
		let _this = this;
		let { item, value } = event,
			{ form_key } = item;
		if (!_this.bluetooth_operate_before_judge()) return;

		item = _this.INIT_COMMAND_CONFIG({ item });
		_this.common_change({ item });
	},
	INIT_COMMAND_CONFIG(event) {
		let _this = this;
		let { item, value } = event;
		let { form_key } = item;
		let init = COMMAND_CONFIG[form_key];
		if (_this.objJudge(init)) {
		} else {
			// 设置初始配置
			init = {
				command_group_code: 0xfa,
				buffer: [0, item['document_start_number'], 1],
			};
		}
		// console.log(init);
		Object.assign(item, init);
		return item;
	},
	CLEAR_STORE_COMMAND_DATA() {
		let _this = this;
		_this.store_set_state({ state_name: 'WRITE_COMMAND_MODE', state_value: 'PARAMETER_NUMBER' });
		_this.store_set_state({ state_name: 'WRITE_COMMAND_DATA', state_value: {} });
		_this.store_set_state({ state_name: 'RESPONSE_COMMAND_MODE', state_value: 'init' });
		uni.removeStorageSync('voltage_calibration_list');
	},
	TIME_TASK(HANDLE = false, TIME = 1000) {
		if (HANDLE) {
			setTimeout(() => {
				HANDLE && HANDLE();
			}, TIME);
		}
	},
	// 模式切换
	CHANGE_RESPONSE_MODE(mode) {
		let _this = this;
		_this.store_set_state({ state_name: 'RESPONSE_COMMAND_MODE', state_value: mode });
	},
	// 值改变触发写入指令
	common_change(config) {
		let _this = this;
		let { item, value } = config;
		let { method_association_key = 'PARAMETER_NUMBER' } = item;
		let MODE = method_association_key;
		if (_this.page_type == 'link_resistance') {
			// 链接内阻调用0xf6
			MODE = _this.page_type;
			item['command_group_code'] = 0xf6;
		} else if (_this.page_type == 'voltage_calibration') {
			// 电压校准
			MODE = _this.page_type;
			let cache_update = [];
			item['command_group_code'] = 0xffaa;
			cache_update.push({ key: form_key, value });
			uni.setStorageSync('voltage_calibration_list', cache_update);
		}
		_this.store_set_state({ state_name: 'WRITE_COMMAND_MODE', state_value: MODE });
		_this.store_set_state({ state_name: 'WRITE_COMMAND_DATA', state_value: item });
		console.log(item, 'common_change');
		_this.log_upload_save({ item, value, step: 0 });
		_this.CHANGE_RESPONSE_MODE('edit');
		if (_this.pagepopup) {
			_this.hidepopup();
		}
		_this.$nextTick(() => {
			if (_this.WEBSOCKET_COMMADN_EDIT) {
				// websocket发送的修改指令不需要提示修改中
			} else {
				// 加载数据loading
				_this.com_loading({ status: 1, title: '修改中...', mask: true });
			}
			let EDIT_KEY = ['DEFAULT_SWITCH', 'CHANGE_POPUP', 'PARAMETER_NUMBER', 'SELECT_PICKER'];
			let EDIT_INDEX = EDIT_KEY.indexOf(_this.WRITE_COMMAND_MODE);

			if (EDIT_INDEX > -1) {
				clearTimeout(_this.READ_RECURRING_TASK);
				_this.READ_RECURRING_TASK = setTimeout(() => {
					_this.editInstruct_init();
				}, 1000);
			} else {
				_this.writeInstruct(item, 0x5a);
			}
		});
	},

	//定义函数
	writeInstruct_init() {
		let _this = this;
		if (!_this.judge_bluetooth()) return;
		console.log('writeInstruct_init');
		// _this.next_write = -2;
		if (_this.objJudge(_this.READ_COMMAND_TASK)) {
			_this.store_set_state({ state_name: 'RESPONSE_COMMAND_MODE', state_value: 'read' });

			_this.READ_COMMAND_TASK.forEach(element => {
				_this.$set(element, 'done', false);
			});
			clearTimeout(_this.READ_RECURRING_TASK);
			_this.READ_RECURRING_TASK = null;
			_this.writeInstruct_task();
		}
	},
	// 按数组顺序进行写入 最后的指令也完成了则重新开始写入
	writeInstruct_task() {
		let _this = this;
		let TASK_INDEX = _this.deepclone(_this.READ_COMMAND_TASK_INDEX);
		// 检查循环任务--start
		let res_index = _this.READ_COMMAND_TASK.findIndex((item, index) => index == TASK_INDEX);
		if (res_index > -1) {
			console.log(`responseInstruct--响应完成--${_this.READ_COMMAND_TASK[res_index].type}`);
			_this.READ_COMMAND_TASK[res_index]['done'] = true;
		}
		let length = _this.READ_COMMAND_TASK.length - 1;
		for (let index = length; index >= 0; index--) {
			let item = _this.READ_COMMAND_TASK[index];
			if (item['done']) {
				// 最后一条读指令
				if (index == length) {
					TASK_INDEX = -2;
					_this.COMMON_CALLBACK('READ_COMMAND_TASK_DONE');
					console.log('结束加载数据loading');
					break;
				} else {
					TASK_INDEX = index + 1;
					break;
				}
			}
			if (index == 0) {
				TASK_INDEX = index;
				break;
			}
		}
		// console.log(_this.next_write, '_this.next_write')
		_this.READ_COMMAND_TASK_INDEX = TASK_INDEX;
		if (TASK_INDEX > -1) {
			// 写入下一个指令
			let time = _this.READ_COMMAND_TASK[TASK_INDEX].time || 50;
			let _item = _this.READ_COMMAND_TASK[TASK_INDEX];
			_this.TIME_TASK(() => {
				_this.writeInstruct(_item);
			}, time);
		} else {
			// next_write -2 已结束整个任务需要全部置空为false
			_this.READ_RECURRING_TASK = setTimeout(() => {
				_this.writeInstruct_init(); // 重新开始
			}, _this.READ_RECURRING_TASK_TIME);
		}
	},
	// 指令初始化
	editInstruct_init() {
		let _this = this;
		if (!_this.judge_bluetooth()) return;

		_this.WRITE_COMMAND_TASK.forEach(element => {
			_this.$set(element, 'done', false);
		});
		console.log(_this.WRITE_COMMAND_TASK);

		console.log('初始化---------------------------task');

		_this.editInstruct_task();
	},

	// 指令任务
	editInstruct_task() {
		let _this = this;
		// 检查循环任务--start
		let TASK_INDEX = _this.COMMADN_EDIT_TASK_INDEX;
		let res_index = _this.WRITE_COMMAND_TASK.findIndex((item, index) => index == TASK_INDEX);

		// console.log(_this.WRITE_COMMAND_TASK);
		// console.log(
		// 	JSON.stringify({
		// 		TASK_INDEX,
		// 		res_index,
		// 		type: 'editInstruct_task',
		// 	})
		// );

		if (res_index > -1) {
			console.log(`responseInstruct--响应完成--${_this.WRITE_COMMAND_TASK[res_index].type}`);
			_this.WRITE_COMMAND_TASK[res_index]['done'] = true;
		}
		// 检查循环任务--end
		let length = _this.WRITE_COMMAND_TASK.length - 1;
		for (let index = length; index >= 0; index--) {
			let item = _this.WRITE_COMMAND_TASK[index];
			if (item['writeForce']) {
				// 初始化写入cmd
				item['command_group_code'] = _this.WRITE_COMMAND_DATA['command_group_code'];
			}

			if (item['done']) {
				// 最后一个退出指令
				if (index == length) {
					TASK_INDEX = -2;
					console.log(TASK_INDEX);
					break;
				} else {
					TASK_INDEX = index + 1;
					console.log(TASK_INDEX);
					break;
				}
			}
			if (index == 0) {
				TASK_INDEX = index;
			}
		}

		// console.log(
		// 	JSON.stringify({
		// 		TASK_INDEX,
		// 		type: '检查完毕',
		// 	})
		// );
		_this.store_set_state({ state_name: 'COMMADN_EDIT_TASK_INDEX', state_value: TASK_INDEX });
		if (TASK_INDEX > -1) {
			// 进入工厂模式-修改参数-退出工厂模式
			let time = _this.WRITE_COMMAND_TASK[TASK_INDEX].time || 50;
			let _item = _this.WRITE_COMMAND_TASK[TASK_INDEX];
			_this.TIME_TASK(() => {
				_this.writeInstruct(_item, 0x5a);
			}, time);
		} else if (TASK_INDEX == -2) {
			// 退出工厂模式后进行查询判断
			_this.CHANGE_RESPONSE_MODE('update');
			_this.TIME_TASK(() => {
				_this.writeInstruct(_this.WRITE_COMMAND_DATA, 0xa5);
			}, 100);
		}
	},
	// 写入 读取参数指令
	writeInstruct(_item, TYPE_ID = 0xa5) {
		let _this = this;
		let { command_group_code: cmd, command_group_id, command_group_buffer, buffer, command_group_forcebuffer } = _item;
		let { popup_key = false, value_type = false } = _this.WRITE_COMMAND_DATA;

		let id = TYPE_ID;
		let buffer_data = [];
		let force_write = [];

		let callback = false;

		// 区分写入id 读取0xa5 写入0x5a 蓝牙模块相关 0xaa
		if (_this.objJudge(command_group_id)) {
			id = command_group_id;
		}

		// 指令数据体
		if (_this.objJudge(command_group_buffer)) {
			buffer_data = command_group_buffer;
		} else if (_this.objJudge(buffer)) {
			buffer_data = buffer;
		}

		// 强制写入覆盖
		if (_this.objJudge(command_group_forcebuffer)) {
			force_write = command_group_forcebuffer;
		}

		if (!_this.judge_bluetooth()) return;

		// 操作蓝牙模块基础指令-------------- start
		if (id == 0xaa) {
			if (cmd == 0x07) {
				// 修改蓝牙名称
				buffer_data = _this.value_handle_arr(popup_key, value_type, _this.WRITE_COMMAND_DATA);
				// 0xff 0xaa 0x07
				force_write = [0xff, 0xaa];
				let _fun = [cmd, buffer_data.length, ...buffer_data];
				_fun = _this.check_buffer(_fun, 'base');
				force_write.push(..._fun);
				// console.log(force_write, 'force_write');
				callback = function () {
					uni.setStorageSync('index_bluetooth_name_cache', popup_key);
				};
			}

			if (cmd == 0xf8) {
				// 查询蓝牙名称
				force_write = [0xff, 0xaa, 0x06, 0x00, 0x06];
			}

			if (cmd == 0xf9) {
				// 读取mac地址
				force_write = [0xff, 0xaa, 0x00, 0x00, 0x00];
			}
		}
		// 操作蓝牙模块基础指令-------------- end

		// 读取-------------- start
		if (id == 0xa5) {
			if (cmd == 0xffaa) {
				// 电压校准后更新
				let cache_update = uni.getStorageSync('voltage_calibration_list');
				_this.responseInstruct(cmd, cache_update);
			}
			if (cmd == 0x00) {
				// 芯片类型
			}

			if (cmd == 0x03) {
				// 读03指令是基本信息及状态，包含容量，总压、电流、温度、保护状态等
			}

			if (cmd == 0x04) {
				// 读04指令是对应电池的电压集合 -- 单个数组 []
			}

			if (cmd == 0x0a) {
				//  读0A指令是读取充电模式 0 普通 1 快充 2均匀 3定时
				callback = function () {
					setTimeout(() => {
						if (_this.BLUETOOTH_INIT_FORM.battery_charge_mode < 0) {
							// 说明该电池不支持选择模式
							_this.responseInstruct();
						}
					}, 1000);
				};
			}

			if (cmd == 0xaa) {
				// 保护统计次数
			}

			if (cmd == 0xad) {
				//  读ad 电流校准
				_this.responseInstruct();
			}

			if (cmd == 0xfa) {
				// 读取FA
			}

			if (cmd == 0xf6) {
				// 读取电池内阻30串
			}
		}
		// 读取-------------- end

		// 写入-------------- start
		if (id == 0x5a) {
			if (cmd == 0x00) {
				// 进入工厂模式
			} else if (cmd == 0x01) {
				// 退出工厂模式
			} else if (cmd == 0xad) {
				// 静态电流校准指令
				buffer_data = _this.value_handle_arr(popup_key, 'default', _this.WRITE_COMMAND_DATA);
			} else if (cmd == 0xf6) {
				// 电池内阻30串
				buffer_data = _this.page_data.link_resistance.list.reduce((pre, next) => {
					let n = _this.BLUETOOTH_INIT_FORM[next.form_key];
					if (next.form_key == _item.form_key) {
						n = _item.popup_key;
					}
					n = _this.value_handle_arr(n, 'resistance');
					pre.push(...n);
					return pre;
				}, []);
			} else if (cmd == 0xfa) {
				// 根据序号修改对应参数
				console.log(_this.WRITE_COMMAND_DATA);
				buffer_data = _this.item_to_editBuffer(_this.WRITE_COMMAND_DATA);
				console.log(buffer_data, '0xFA写入参数');
			} else if (cmd == 0xfb) {
				//  控制充电 放电MOS开关
			} else if (cmd == 0x0a) {
				// DD5A0A 02 0100 FFF377
				// 发送自动均衡 清除告警 重置容量指令 0x0A
			} else if (cmd == 0xffaa) {
				// 电压校准
				buffer_data = _this.value_handle_arr(popup_key, 'default', _this.WRITE_COMMAND_DATA);
				console.log(buffer_data, cmd, _this.edit_write_data, '电压校准');
			}
		}
		// 写入-------------- end
		let WRITE_CONFIG = {
			id,
			cmd,
			_buffer: buffer_data,
			force_write,
			callback,
		};
		// console.log(force_write, 'force_write');
		// console.log(_this.WRITE_COMMAND_DATA);
		// console.log(_this.WRITE_COMMAND_MODE);
		WRITE_CONFIG['dataLen'] = buffer_data.length;
		console.log(WRITE_CONFIG);
		_this.writeBufferToBLE(WRITE_CONFIG);
	},
	item_to_editBuffer(item) {
		let _this = this;
		let { document_start_number, popup_key, value_type = 'default' } = item;
		let _arr = [];

		// 参数对应序号的高低位
		_arr.push(..._this.num_to_highlow(document_start_number).hl);
		// 修改参数个数 默认一个

		_arr.push(1);

		if (_this.objJudge(item.unit_read_conversion)) {
			// 精度转换 A转 mA 就会乘 1000
			popup_key = Math.floor(popup_key / (item.unit_read_conversion * item.unit_read_compute));
		}

		let _buffer = _this.value_handle_arr(popup_key, value_type, item);
		// debugger
		_arr.push(..._buffer);
		// debugger
		return _arr;
	},
	// 当前指令已完成
	responseInstruct(cmd, update_echo = []) {
		let _this = this;
		let mode = _this.RESPONSE_COMMAND_MODE;
		switch (mode) {
			case 'init':
				break;
			case 'read':
				_this.COMMON_CALLBACK('READ_COMMAND_TASK_RESPONSE');
				break;
			case 'edit':
				// 修改成功后执行对应的查询
				_this.responseInstruct_callback(cmd, update_echo);
				break;
			case 'update':
				_this.common_change_update(cmd, update_echo);
				break;
		}
	},

	responseInstruct_callback(cmd, update_echo) {
		let _this = this;
		switch (_this.WRITE_COMMAND_MODE) {
			case 'DEFAULT_SWITCH':
				_this.editInstruct_task();
				break;
			case 'MOS_SWITCH':
				// MOC指令充放电开关
				_this.CHANGE_RESPONSE_MODE('update');
				_this.TIME_TASK(() => {
					_this.writeInstruct({ command_group_code: 0x03 }, 0xa5);
				}, 1000);
				break;
			case 'PARAMETER_NUMBER':
				// 序号查询
				_this.editInstruct_task();
				break;
			case 'CHANGE_POPUP':
				// 电流校准
				_this.editInstruct_task();
				break;
			case 'CONFIRM_POPUP':
				// 自动均衡 清除告警 重置容量
				_this.CHANGE_RESPONSE_MODE('update');
				_this.TIME_TASK(() => {
					_this.responseInstruct();
				}, 1000);
				break;
			case 'SELECT_PICKER':
				_this.editInstruct_task();
				break;
			case 'MODE_SELECT':
				// 选择模式完成后进行 模式读取判断是否切换成功
				_this.CHANGE_RESPONSE_MODE('update');
				_this.TIME_TASK(() => {
					_this.writeInstruct({ command_group_code: 0x0a, buffer: [0x11] }, 0xa5);
				}, 1000);
				break;
			case 'bluetooth_device_name':
				_this.CHANGE_RESPONSE_MODE('update');
				_this.responseInstruct(cmd, update_echo);
				break;
			case 'link_resistance':
				// 查询内阻并更新
				_this.CHANGE_RESPONSE_MODE('update');
				_this.writeInstruct(_this.edit_write_data, 0xa5);
				break;
			case 'voltage_calibration':
				// 电压校准
				_this.editInstruct_task();
				break;
		}
	},
	// 最后完成动作
	common_change_update(cmd, update_echo = []) {
		let _this = this;
		_this.CLEAR_STORE_COMMAND_DATA();
		_this.update_pagedata(update_echo);
		if (_this.WEBSOCKET_COMMADN_EDIT) {
			_this.store_set_state({ state_name: 'WEBSOCKET_COMMADN_EDIT', state_value: false });
		} else {
			_this.log_upload_save({
				step: 1,
				callback: function () {
					_this.com_loading({ status: 2, title: '修改成功', mask: true });
				},
			});
		}
	},
	// 根据配置取相关联的16位数组然后进行循环取值 输出一个二进制数组再反转取值
	switch_getvalue_fun(e) {
		let { item, value } = e;
		console.log(e);
		let _this = this;
		let end_key = 0;
		let retrieval_l = [
			{
				config_name: 'balanced_setting_enable_balance',
				config_list: [
					'function_setting_switch',
					'function_setting_load_detection',
					'function_setting_balance',
					'function_setting_balance_mode',
					'function_setting_led',
					'function_setting_led_quantity',
					'function_setting_rtc',
					'function_setting_fcc_limit',
					'function_setting_handshake_enable',
					'function_setting_gps',
					'function_setting_buzzer_enable',
					'function_setting_battery_mode',
					'function_setting_current_capacity',
					'',
					'',
					'',
				],
			},
			{
				config_name: 'temperature_probe_configuration',
				config_list: [
					'function_setting_temp_1',
					'function_setting_temp_2',
					'function_setting_temp_3',
					'function_setting_temp_4',
					'function_setting_temp_5',
					'function_setting_temp_6',
					'function_setting_temp_7',
					'function_setting_temp_8',
				],
			},
		];
		_this.find_to_handle({
			data: retrieval_l,
			find_fun: function (e) {
				let { data, attr_name, find_fun } = e;
				// attr_name == 'form_key'
				if (_this.gettype(data) == 'Array' && data.indexOf(item.form_key) > -1) {
					let arr = [];
					data.forEach((_d, _i) => {
						if (_this.objJudge(_d)) {
							// console.log(item.form_key, _d, _i)
							if (item.form_key == _d) {
								// value = value == 1 ? 0 : 1;
								arr.push(value);
							} else {
								arr.push(_this.BLUETOOTH_INIT_FORM[_d]);
							}
						} else {
							arr.push(0);
						}
					});
					end_key = _this.twoarr_to_num(arr);
					console.log(end_key, arr, 'switch_getvalue_fun_1');
				} else {
					return false;
				}
			},
		});

		return end_key;
	},
	BACK_COMMAND_METHOD_NAME(k) {
		let NAME = false;
		for (let index = 0; index < COMMAND_METHOD_DESIGNATE.length; index++) {
			const element = COMMAND_METHOD_DESIGNATE[index];
			let i = element.method_association.indexOf(k);
			// console.log(element);
			// console.log(i);
			if (i > -1) {
				NAME = element.method_name;
				break;
			}
		}
		return NAME;
	},

	// 测试指令
	START_TEST_COMMADN() {
		let _this = this;
		setTimeout(() => {
			_this.test_read('DD030026146900000CDA1B5800022D59000000000000382F030E030BD40BC00BBE0000001B580CDA0000F93577');

			_this.test_read(
				'DDFA00730000381B5815E010360BB800012D59000000020D350CD10A470A790D990D3509E30A47173E16B20F0A1068109A10360ABE0BB807D0E8900ED8000F00020006002F000E001E000A0F780EEC0E600D7A10CC09C4004000E00032000500050006000500050002000200030003000D0020000A0020EA7D77'
			);
			_this.test_read(
				'DDFA00630038300544474A424420202020202020202020202020202020202020202020202020200F535031375330303450313453353041202020202020202020202020202020201231363736303030333232313032353230383120202020202020202020202020EFA677'
			);
			_this.test_read(
				'DDFA006F0068360C1C00780FBE0F320EA60DFC0CE410041B580E10020600320A1E024C0032000A050F0320003C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F89477'
			);
			_this.test_read('DDFA0037009E1A0F53503137533030345031345335304120202020202020200000000000000000000000000F53503232533030312056312E300000F76377');
			// _this.test_read('DD0000020001FFFD77');
			// _this.test_read('DDF6003C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFC477');
			// _this.test_read('DDAA0018000000000000000000000000000000000000000000000001FFE777');
			_this.test_read('DD04001C0E930E920E930E930E930E920E930E930E930E930E8F0E990E970EA0F70577');
		}, 1500);

		// setTimeout(() => {
		// 	_this.GET_SOCKET_MESSAGE_TYPE({
		// 		dev_id: 'A5:C2:37:00:2D:3C',
		// 		type: 'cmd',
		// 		msg: { key: 'protection_parameters_overvoltage_delay', value: '4' },
		// 		token: 'AABBCC',
		// 		time: new Date(),
		// 	});
		// }, 2000);
	},
};
